1. 依赖 Butterknife

Butterknife 已经支持 library 使用 R2,所以框架是支持使用 Butterknife。

  • baselib build.gradle 中添加依赖
1
compile 'com.jakewharton:butterknife:8.8.1'
  • 根目录的 build.gradle 添加:
1
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'

插件 8.4.0以上与 gradle 3.0 有冲突

  • app、module 中分别依赖
1
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
  • module build.gradle 添加插件 :
1
apply plugin: 'com.jakewharton.butterknife'

对于app module,作为main Module,使用R或者R2类都不影响,对于其他的library 类型的 module,注意:layout资源依旧使用R类,id类、String类资源需要使用R2类。点击事件判断,不能使用 switch ,需用 if 判断,且使用 R。

2. 依赖 ARouter

ARouter 可利用注解方便的进行 UI 跳转

  • baselib build.gradle 中添加依赖
1
compile 'com.alibaba:arouter-api:1.2.4'
  • app、module 中分别依赖
1
annotationProcessor 'com.alibaba:arouter-compiler:1.1.4'
  • app、module 中的 application 分别初始化 ARouter
1
2
3
4
5
6
if (BuildConfig.DEBUG) {
ARouter.openLog();
ARouter.openDebug();
}
ARouter.init(this);

3. 组件应用 application

方法:

  • 主项目提供一个接口返回ApplicationContext
  • 将BaseApplication抽离到basicres或者basiclib里面,在BaseApplication提供一个静态方法来获取ApplicationContext。

4. 模拟数据

组件独立调试引用其他组件数据需模拟数据

5. 自己定制包名

componentlib 使用自己的包名需要在插件中同步更改

1
2
3
4
5
6
7
8
9
10
11
12
13
private boolean isActivator(CtClass ctClass) {
try {
for (CtClass ctClassInter : ctClass.getInterfaces()) {
if ("com.atu.componentlib.applicationlike.IApplicationLike".equals(ctClassInter.name)) {
return true;
}
}
} catch (Exception e) {
println "class not found exception class name: " + ctClass.getName()
}
return false;
}

包名需以 com 开头